﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SolutionModel;
using SolutionBLL;
using System.Web;

namespace SolutionCommon
{
    public static class LogCom
    {

        /// <summary>
        /// 记录错误信息
        /// </summary>
        /// <param name="ex"></param>
        public static void errorLog(Exception ex)
        {
            T_Error error = new T_Error();
            Exception exc = ex.InnerException;
            if (ex.InnerException != null)
            {
                error = new T_Error();
                error.Title = exc.Message;
                error.Url = HttpContext.Current.Request.RawUrl;
                error.ErrorType = exc.GetBaseException().GetType().FullName;
                error.Record = exc.StackTrace.Replace("\r\n", "<br />").Trim();
                error.CreateTime = DateTime.Now;
            }
            else
            {
                error = new T_Error();
                error.Title = ex.Message;
                error.Url = HttpContext.Current.Request.RawUrl;
                error.ErrorType = ex.GetBaseException().GetType().FullName;
                error.Record = ex.StackTrace.Replace("\r\n", "<br />").Trim();
                error.CreateTime = DateTime.Now;
            }
            if (error != null)
            {
                T_ErrorBLL bll = new T_ErrorBLL();
                bll.Add(error);
            }
        }
    }
}
